<template>
  <div class="app-container">
    <!-- 搜索筛选操作栏 -->
    <div class="filter-container clearfix">
      <el-input
        v-model="listQuery.name"
        placeholder="请输入店铺名称"
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      <el-select
        v-model="listQuery.type"
        placeholder="请选择类型"
        clearable
        style="width: 150px; margin-left: 10px"
        class="filter-item"
      >
        <el-option label="缴纳" :value="0" />
        <el-option label="扣除" :value="1" />
        <el-option label="闭店提现" :value="2" />
        <el-option label="退货返还" :value="3" />
        <el-option label="支付逾期" :value="4" />
      </el-select>
      <el-button
        v-waves
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        style="margin-left: 10px"
        @click="handleFilter"
      >
        搜索
      </el-button>
      <el-button
        v-waves
        class="filter-item"
        icon="iconfont qt-caozuo-xunhuan1"
        @click="clearFilter"
      >
        重置
      </el-button>
    </div>

    <!-- 表格 -->
    <el-table
      :key="tableKey"
      ref="table"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column label="账号" prop="user.user" align="center" />
      <el-table-column label="店铺名称" align="center">
        <template slot-scope="{ row }">
          {{
            (row.shopping && row.shopping.name) ||
              (row.shopping && row.shopping.shopping_name)
          }}
        </template>
      </el-table-column>
      <el-table-column label="类型" align="center">
        <template slot-scope="{ row }">
          {{
            row.type == 0
              ? "缴纳"
              : row.type == 1
                ? "扣除"
                : row.type == 2
                  ? "闭店提现"
                  : row.type == 3
                    ? "退货返还"
                    : row.type == 4
                      ? "支付逾期"
                      : ""
          }}
        </template>
      </el-table-column>
      <el-table-column label="金额" align="center" prop="money" />
      <el-table-column label="支付方式" align="center">
        <template slot-scope="{ row }">
          {{
            row.pay_type == 0
              ? "支付宝"
              : row.pay_type == 1
                ? "微信"
                : row.pay_type == 2
                  ? "银行卡"
                  : row.pay_type == 3
                    ? "微信公众号"
                    : row.pay_type == 4
                      ? "后台添加"
                      : ""
          }}
        </template>
      </el-table-column>
      <el-table-column label="操作后余额" align="center" prop="balance_money" />
      <el-table-column align="center" label="操作时间" prop="created_at" />
    </el-table>

    <!-- 分页 -->
    <div v-if="total > 0" style="text-align: right">
      <pagination
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.per_page"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { getShoppingdeposit } from '@/api/common'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination

export default {
  name: 'MerchantsDeposit',
  components: {
    Pagination
  },
  directives: {
    waves
  },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        per_page: 20,
        name: undefined,
        type: undefined
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    clearFilter() {
      this.listQuery['name'] = undefined
      this.listQuery['type'] = undefined
      this.handleFilter()
    },
    getList() {
      this.listLoading = true
      getShoppingdeposit(this.listQuery)
        .then((response) => {
          const { data, total } = response.data
          this.list = data
          this.total = total
        })
        .finally(() => {
          this.listLoading = false
        })
    }
  }
}
</script>
